/* 	MediaStream
*	Display group
*	
*	IMPORTANT
*
*	
*										*/
var MediaStream = function( vars )	{

	Object.extend( obj = $$( '.MediaStream' ).pop(), MediaStream.proto );
	//Object.extend( obj, CalendarField[ "proto_" + ref.react ]);
	//obj.ref = ref;
	
	//obj.init();
	if( vars )	obj.vars = vars;
	//if( set ) 	obj.seed( set );
	
	this.children = obj.select('li.group .title');
	this.children.each( function( el ) {
		el.observe( "click", function( e ){ this.up().toggleClassName( "active" ); } );
	} );

	return obj;
}


MediaStream.proto = {
	
	current		: 0,
	
	load		: function( el ) {
		
		this.current += ( el.currentTarget.hasClassName( "left" ) )? -1 : 1;
		this.select( ".month" )[0].update( "..." );
		
		xhttp.send( '/xhttp.mod', { mod: "calendar.field", action: "mini", vars: { current: this.current }}, this.pull_response.bind( this ));
	},
	
	seed		: function( set ) {
		
		
	},
	
	slideshow	: function() {
	
		this.select( 'a.navigate' ).each( function( el ) {
			
			el.observe( 'click', this.fader.bind( this, el ));
		}, this );
	},
	
	fader		: function( el ) {
	
		this.select( 'a.navigate' ).each( function( el ) {
			el.removeClassName( 'active' );
		});
		el.addClassName( 'active' );

		this.select( 'li.movie.active' ).each( function( el ) {
			el.removeClassName( 'active' );
			el.addClassName( 'hide' );
		});
		
		$( 'ref' + el.rel ).addClassName( 'active' );
	
	},
	
	fillnode	: function( span, n) {
			
			
	},
	
	slideshow	: function() {
	
		this.select( 'a.navigate' ).each( function( el ) {
			
			el.observe( 'click', this.fader.bind( this, el ));
		}, this );
	},
	
	fader		: function( el ) {
	
		this.select( 'a.navigate' ).each( function( el ) {
			el.removeClassName( 'active' );
		});
		el.addClassName( 'active' );

		this.select( 'li.movie.active' ).each( function( el ) {
			el.removeClassName( 'active' );
			el.addClassName( 'hide' );
		});
		
		$( 'ref' + el.rel ).addClassName( 'active' );
	
	},
	
	dominate	: function ( ref ) {
	
		this.select( "li.image" ).each( function ( el ) {
			el.observe( "click", this.change.bind( this, ref, el ) );
		}, this );
	
	},
	
	change			: function( ref, el ) {
		
		var id	= el.down().identify();
		xhttp.send( '/xhttp.mod', { mod: "media.stream", action: "fill", vars: { id: id, vars: this.vars }}, this.pull_response.bind( this, ref ));
			
	},
	
	pull_response	: function( ref, response ) {
	
		set = response.responseText;
		$( ref ).update( set );
	
	},
	
	expand		: function( cond ) {
		
		if( cond == "first" ) this.children[0].children[0].addClassName( "active" );
		else if( !cond ) this.children.invoke( "addClassName", "active");
		else for( n=0; n<cond; n++ ) chlidren[ n ].addClassName( "active" );
	},

	
	prepstream		: function() {
		
		this.select( ".playIt" ).each( function( el ) {
			
			el.observe( "click", this.flipstream );
		}, this );
		
	},
	
	flipstream		: function() {

		var childs = this.up(1).childElements();
		childs[0].hide();
		childs[1].hide();
		childs[2].removeClassName("hide");
		
	},
	
	bubble		: function() {}

}

MediaStream.proto_info = {
	
	init		: function() {
	
	},
	
	hover		: function() {

	},
	
	bubble		: function() {
		
	}
}